import { MiddlewareConsumer, Module, NestModule } from "@nestjs/common"
import * as cookieParser from "cookie-parser"
import * as session from "express-session"
import { sessionConfig } from "./config/session"
import { moduleConfig } from "./config/module"
import { AuthorMiddleware } from "./middleware/author.middleware"
import { LoginMiddleware } from "./middleware/login.middleware"

@Module({
  imports: moduleConfig,
  controllers: [],
  providers: []
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(session(sessionConfig)).forRoutes("*")
    consumer.apply(cookieParser()).forRoutes("*")
    // 安全验证
    consumer.apply(AuthorMiddleware).forRoutes("/authorization")
    // 过期验证
    consumer.apply(LoginMiddleware).forRoutes("/program")
  }
}
